package com.mlh.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.mlh.entity.Link;
import com.mlh.mapper.LinkMapper;
import com.mlh.service.LinkService;
import com.mlh.util.BeanCopyUtil;
import com.mlh.util.ResponseResult;
import com.mlh.vo.LinkAllListVo;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

/**
 * 友链(Link)表服务实现类
 *
 * @author makejava
 * @since 2024-03-13 11:50:59
 */
@Service("linkService")
public class LinkServiceImpl extends ServiceImpl<LinkMapper, Link> implements LinkService {
    @Override
    public ResponseResult getAllLink() {
        LambdaQueryWrapper<Link> lambdaQueryWrapper=new LambdaQueryWrapper<>();
        //筛选出审核通过的友联
        lambdaQueryWrapper.eq(Link::getStatus,"0");
        List<Link> list = list(lambdaQueryWrapper);
        //转换成vo
        List<LinkAllListVo> linkAllListVos = list.stream()
                .map(link -> BeanCopyUtil.copyBean(link, LinkAllListVo.class))
                .collect(Collectors.toList());
        return ResponseResult.okResult(linkAllListVos);
    }
}
